package com.zhuojy.equity.mall.admin.service.car;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.TCar;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.dal.mapper.car.TCarMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xrz
 * @version 1.0
 * @description:TODO
 * @date 2024/3/27 17:14
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TCarService extends ServiceImpl<TCarMapper, TCar> {

    public ResultEntity getCarList(TCar tCar, Integer pageSize, Integer pageNum) {
        Page<TCar> page = new Page<>(pageNum, pageSize);
        IPage<TCar> tCarPage = this.baseMapper.findCarPagination(tCar, page);
        return ResultEntity.OK(tCarPage);
    }

    public ResultEntity getCarNumber() {
        QueryWrapper<TCar> wrapper = new QueryWrapper<>();
        wrapper.select("car_number","id");
        List<TCar> tCars = this.baseMapper.selectList(wrapper);
        return ResultEntity.OK(tCars);
    }

    public ResultEntity addCar(TCar tCar) {
        this.baseMapper.insert(tCar);
        return ResultEntity.OK("添加成功");
    }

    public ResultEntity getCarById(Integer id) {
        TCar tCar = this.baseMapper.selectById(id);
        return ResultEntity.OK(tCar);
    }

    public ResultEntity updateCar(TCar tCar) {
        int i = this.baseMapper.updateById(tCar);
        return ResultEntity.OK("修改成功");
    }

    public ResultEntity deleteCarById(Integer id) {
        int i = this.baseMapper.deleteById(id);
        return ResultEntity.OK("删除成功");
    }
}
